/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-01
 * Time: 19:03
 */
import java.util.*;
public class Solution2 {
    public void merge(int A[], int m, int B[], int n) {
        int len1 = A.length;
        int[] arr = new int[len1];
        int iA = 0;
        int iB = 0;
        int nowIndex = 0;
        while(iA < m && iB < n) {
            if(A[iA] < B[iB]) {
                arr[nowIndex] = A[iA];
                nowIndex++;
                iA++;
            }else {
                arr[nowIndex] = B[iB];
                nowIndex++;
                iB++;
            }
        }
        if(iA == m) {
            for (int i = iB; i < n; i++) {
                arr[nowIndex] = B[i];
                nowIndex++;
            }
        }
        if(iB == n) {
            for (int i = iA; i < m; i++) {
                arr[nowIndex] = A[i];
                nowIndex++;
            }
        }
        for (int i = 0; i < len1; i++) {
            A[i] = arr[i];
        }
    }

    public static void main(String[] args) {
        int[] A = {4,5,6,0,0,0};
        int[] B = {1,2,3};
        Solution2 solution2 = new Solution2();
        solution2.merge(A,3,B,3);
        System.out.println(Arrays.toString(A));
    }
}
